package tech.aistar.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tech.aistar.pojo.Order;

import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 根据订单id查询
     */
    Order findById(String orderId);

    /**
     * 根据user_id和send_time查询
     */
    List<Order> findByUserId(Integer userId);

    /**
     * 生成订单
     * @param order
     * @return
     */
    Integer initOrder(Order order);

    /**
     * 取消订单
     * @param orderId
     * @param userId
     * @return
     */
    @Update("update order_status set status = 2 where order_id = #{orderId} and user_id = #{userId}")
    Integer cancelOrder(String orderId,Integer userId);

    /**
     * 删除订单记录
     */
    Integer delOrder(String orderId);

    /**
     * 修改订单地址
     */
    @Update("update order_status set address = #{address} where order_id = #{orderId} and user_id = #{userId}")
    Integer updateOrderAddress(String orderId,Integer userId,String address);

    /**
     * 修改订单留言
     */
    @Update("update order_status set note = #{note} where order_id = #{orderId} and user_id = #{userId}")
    Integer updateOrderNote(String orderId,Integer userId,String note);

    /**
     * 修改送达时间
     * @param orderId
     * @param userId
     * @param sendTime
     */
    @Update("update order_status set send_time = #{sendTime} where order_id = #{orderId} and user_id = #{userId}")
    Integer updateOrderSendTime(String orderId, Integer userId, String sendTime);

    @Select("select * from order_status where user_id = #{userId};")
    List<Order> getOrderStatusListByUserId(Integer userId);

    @Select("select flower_id from `order` where order_id = #{orderId};")
    List<Integer> getFlowerIdsByOrderId(String orderId);

    @Select("select `count` from `order` where order_id = #{orderId}")
    List<Integer> getCountsByOrderId(String orderId);

    @Select("select order_id from `order_status` where user_id = #{userId};")
    List<String> getOrderIdsByUserId(Integer userId);

    @Select("select send_time from `order_status` where user_id = #{userId}")
    List<String> getSendTimesByUserId(Integer userId);
}
